app.controller('specificationController', function ($scope,$controller,specificationService) {

    //控制器继承
    //继承baseController控制器，且把父控制器$scope传递子控制器的$scope
    $controller("baseController",{$scope:$scope});

    //分页查询方法
    $scope.findPage = function (page, rows) {
        specificationService.findPage(page,rows).success(function (data) {
            $scope.list = data.rows;
            $scope.paginationConf.totalItems = data.total;
        })
    };

    //    添加方法
    $scope.save = function () {
        var objService = null;
        //判断是否是修改操作，还是保存操作
        if ($scope.entity.specification.id != null) {
            objService = specificationService.update($scope.entity);
        }else{
            //否则添加
            objService = specificationService.add($scope.entity);
        }

        objService.success(function (response) {
            if (response.success) {
                $scope.reloadList();
            } else {
                alert(response.message);
            }
        })
    };

    //    查询一条记录方法
    $scope.findOne = function (id) {
        specificationService.findOne(id).success(function (data) {
            $scope.entity = data;
        })
    };


    //    删除方法
    $scope.del = function () {
        specificationService.del($scope.selectIds).success(function (data) {
            if(data.success){
                $scope.reloadList();
            }else {
                alert($scope.message);
            }
        })
    };

    // $scope.entity.specificationOptionList = [];
    // entity = {specification:{},specificationOptionList:[]};
    $scope.addTableRow = function () {
        $scope.entity.specificationOptionList.push({});
    };

    $scope.deleTableRow = function (index) {
        $scope.entity.specificationOptionList.splice(index,1);
    }

});